<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <link rel="stylesheet" href="http://www.petercorke.com/RVC/common/toolboxhelp.css">
    <title>M-File Help: ipixswitch</title>
  </head>
  <body>
  <table border="0" cellspacing="0" width="100%">
    <tr class="subheader">
      <td class="headertitle">M-File Help: ipixswitch</td>
      <td class="subheader-left"><a href="matlab:open ipixswitch">View code for ipixswitch</a></td>
    </tr>
  </table>
<h1>ipixswitch</h1><p><span class="helptopic">Pixelwise image merge</span></p><p>
<strong>out</strong> = <span style="color:red">ipixswitch</span>(<strong>mask</strong>, <strong>im1</strong>, <strong>im2</strong>) is an image where each pixel is
selected from the corresponding pixel in <strong>im1</strong> or <strong>im2</strong> according to the
corresponding pixel values in <strong>mask</strong>.  If the element of <strong>mask</strong> is zero <strong>im1</strong> is
selected, otherwise <strong>im2</strong> is selected.

</p>
<p>
<strong>im1</strong> or <strong>im2</strong> can contain a color descriptor which is one of:

</p>
<ul>
  <li>A scalar value corresponding to a greyscale</li>
  <li>A 3-vector corresponding to a color value</li>
  <li>A string containing the name of a color which is found using COLORNAME.</li>
</ul>
<p>
<span style="color:red">ipixswitch</span>(<strong>mask</strong>, <strong>im1</strong>, <strong>im2</strong>) as above but the result is displayed.

</p>
<h2>Example</h2>
<p>
Read a uint8 image

</p>
<pre style="width: 90%%;" class="examples">
im&nbsp;=&nbsp;iread('lena.pgm');
</pre>
<p>
and set high valued pixels to red

</p>
<pre style="width: 90%%;" class="examples">
a&nbsp;=&nbsp;ipixswitch(im>120,&nbsp;im,&nbsp;uint8([255&nbsp;0&nbsp;0]));
</pre>
<p>
The result is a uint8 image since both arguments are uint8 images.

</p>
<pre style="width: 90%%;" class="examples">
a&nbsp;=&nbsp;ipixswitch(im>120,&nbsp;im,&nbsp;[1&nbsp;0&nbsp;0]);
</pre>
<p>
The result is a double precision image since the color specification
is a double.

</p>
<pre style="width: 90%%;" class="examples">
a&nbsp;=&nbsp;ipixswitch(im>120,&nbsp;im,&nbsp;'red');
</pre>
<p>
The result is a double precision image since the result of colorname
is a double precision 3-vector.

</p>
<h2>Notes</h2>
<ul>
  <li>IM1, IM2 and MASK must all have the same number of rows and columns.</li>
  <li>If IM1 and IM2 are both greyscale then OUT is greyscale.</li>
  <li>If either of IM1 and IM2 are color then OUT is color.</li>
  <li>If either one image is double and one is integer then the integer
image is first converted to a double image.</li>
</ul>
<h2>See also</h2>
<p>
<a href="matlab:doc colorize">colorize</a>, <a href="matlab:doc colorname">colorname</a></p>
<hr>

<table border="0" width="100%" cellpadding="0" cellspacing="0">
  <tr class="subheader" valign="top"><td>&nbsp;</td></tr></table>
<p class="copy">&copy; 1990-2012 Peter Corke.</p>
</body></html>